package com.augn.service.impl;

import com.augn.entity.Goods;
import com.augn.entity.GoodsEvaluateFrom;
import com.augn.entity.Result;
import com.augn.entity.Style;
import com.augn.mapper.StyleMapper;
import com.augn.service.IStyleService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author augn
 * @since 2022-09-22
 */
@Service
public class StyleServiceImpl extends ServiceImpl<StyleMapper, Style> implements IStyleService {

    @Autowired
    private StyleMapper mapper;

    @Override
    public Result<?> insertOneStyle(Style style) {
        int insert = mapper.insert(style);
        if(insert==0){
            return Result.error("-1","新增失败");
        } else{
            return Result.success(insert);
        }
    }

    @Override
    public Result<?> deleteOneStyle(Integer id) {
        int delete = mapper.deleteById(id);
        if(delete==0){
            return Result.error("-1","删除失败");
        } else{
            return Result.success(delete);
        }
    }

    @Override
    public Result<?> updateOneStyle(Style style) {
        int update = mapper.updateById(style);
        if(update==0){
            return Result.error("-1","更新失败");
        } else{
            return Result.success(update);
        }
    }

    @Override
    public Result<?> getPartStyle(Integer id) {
        QueryWrapper<Style> wrapper= new QueryWrapper<>();
        wrapper.eq("goods_id",id);
        List<Style> selectList = mapper.selectList(wrapper);
        if(selectList.isEmpty()){
            return Result.error("-1","此商品只有一款");
        } else{
            return Result.success(selectList);
        }
    }

    @Override
    public Result<?> getOneStyle(Integer id) {
        Style style = mapper.selectById(id);
        if(style==null){
            return Result.error("-1","无此款式");
        } else{
            return Result.success(style);
        }
    }
}
